package org.yx.service.smfr.view_production_order;

import com.xiaoleilu.hutool.util.StrUtil;
import org.dbist.dml.Query;
import org.yx.models.SbasProdMat;
import org.yx.models.SmfrOrdDef;
import org.yx.utils.BaseService;

import java.util.ArrayList;
import java.util.List;

/**
 * 查询生产订单信息
 * @author zxw
 * @since 2018/04/19
**/
public class SmfrViewProductionOrderService extends BaseService {
	public SmfrViewProductionOrderOut viewProductionOrder(SmfrViewProductionOrderIn in) throws Exception {
		if (StrUtil.isBlank(in.getMo())) {
			return new SmfrViewProductionOrderOut();
		}

		Query query = new Query();
		query.addFilter("orgCode", in.getUserOrgCode());
		query.addFilter("mo", in.getMo());
		List<SmfrOrdDef> ordList = selectList(SmfrOrdDef.class, query);
		List<ProductionOrder> orders = new ArrayList<ProductionOrder>();
		for (SmfrOrdDef order : ordList) {
			ProductionOrder mo = new ProductionOrder();
			copyProperties(order, mo);

			SbasProdMat prod = selectOne(SbasProdMat.class, in.getUserOrgCode(), mo.getMatCode(), mo.getMatVer());
			if (prod != null) {
				mo.setMatDesc(prod.getMatDesc());
				mo.setMatSpec(prod.getMatSpec());
			}
			orders.add(mo);
		}

		SmfrViewProductionOrderOut out = new SmfrViewProductionOrderOut();
		out.setOrderList(orders);

		return out;
	}
}